package com.androider.timememory.utils;

import java.io.File;
import java.lang.ref.WeakReference;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

public class FileUtil {
	public static final String SD_DIR = Environment.getExternalStorageDirectory().toString() + File.separator;
	
	public static final String RECORD_PICTURE_DIR = SD_DIR + "TimeMemory/picture/";
	public static final String RECORD_VIDEO_DIR = SD_DIR + "TimeMemory/video/";
	public static final String RECORD_AUDIO_DIR = SD_DIR + "TimeMemory/audio/";
	
	public static final String RECORD_VIDEO_THUMBNAIL_DIR = SD_DIR + "TimeMemory/video_thumbnail/";
	public static final String RECORD_PICTURE_THUMBNAIL_DIR = SD_DIR + "TimeMemory/picture_thumbnail/";
	public static final String RECORD_PICTURE_SMALL_THUMBNAIL_DIR = SD_DIR + "TimeMemory/picture_small_thumbnail/";
	public static final String RECORD_VIDEO_SMALL_THUMBNAIL_DIR = SD_DIR + "TimeMemory/video_small_thumbnail/";
	
	public static String getPictureDir() {
		return RECORD_PICTURE_DIR;
	}

	public static String getFileName(String fullName) {
		int pos = fullName.lastIndexOf(".");
		if(pos != -1) {
			return fullName.substring(0, pos);
		}
		return fullName;
	}
	
	/**
	 * Get the file name only, not including path and suffix
	 * @param fullPath
	 * @return
	 */
	public static String getFileNameFromPath(String fullPath) {
	    int start = fullPath.lastIndexOf("/");
	    int end = fullPath.lastIndexOf(".");
	    if(start != -1 && end != -1) {
	        return fullPath.substring(start, end + 1);
	    }
	    return null;
	}
	
	public static boolean createDirectory(String dir) {
		File file = new File(dir);
		if(!file.exists()) {
			if(!file.mkdirs()) {
				if(file.exists() && file.isDirectory()) {
					return true;
				} else {
					return false;
				}
			}
		}
		return true;
	}
}
